let $fn = function() {

	var This = this;
	This.data = {
		rList: [],
		searchValue: {},
		searchVerify: {}
	};
	This.searchInit = function() {
		This.$nameArray = []
		This.searchList = []
		This.indexOfName = function() {
			//遍历匹配
			This.data.rList.map(function(v) {
				if(This.searchValue(v) && This.searchVerify(v)) {
					var nameStatus = true
					for(let i = 0; i < This.$nameArray.length; i++) {
						if(This.$nameArray[i].uuid == v.uuid) {
							nameStatus = false
							break;
						}
					}
					nameStatus && This.$nameArray.push(v)
				}
			})
		}
	}
	This.searchValue = function(ValueObj) {
		var $res = []
		for(var k in This.data.searchValue){
			var v = This.data.searchValue[k]
			var $text = v.replace(/，/g, ",").replace(/\s/g, "")
			$res.push(0)
			//单个模糊词
			if($text) {
				$text.split(",").map(function(t) {
					//单个模糊词内分词
					if(ValueObj[k]) {
						if(ValueObj[k].indexOf(t) > -1) {
							$res[$res.length - 1] = 1
						}
					}
				})
			} else {
				$res[$res.length - 1] = 1
			}
		}
		return($res.toString().indexOf("0") > -1) ? false : true
	}
	This.searchVerify = function(verifyObj) {
		var $res = true
		for(var k in This.data.searchVerify){
			var v = This.data.searchVerify[k]
			if(verifyObj[k] && verifyObj[k] != v && v) {
				$res = false
			}
		}
		return $res
	}

	return {
		setList: function(list, config) {
			This.data.list = list
			This.data.rList = list
			This.searchInit()
			This.data.pageConfig = config
			if(config && config.pageId) {
				layui.laypage.render({
					elem: config.pageId || 'laypage',
					count: This.data.list.length,
					limit: config.limit || 10,
					jump: function(obj, first) {
						$$timeout(function() {
							config.result && config.result($$.page(This.data.list, obj.curr, obj.limit, This))
						})
					}
				})
			}
		},
		setSearchValue: function(Value) {
			This.data.searchValue = Value
		},
		setSearchVerify: function(verify) {
			This.data.searchVerify = verify
		},
		search: function(callback) {
			This.$nameArray = []
			This.indexOfName()
			This.data.list = This.$nameArray
			This.callback = callback
			var $config = This.data.pageConfig
			if($config && $config.pageId) {
				layui.laypage.render({
					elem: $config.pageId || 'laypage',
					count: This.data.list.length,
					limit: $config.limit || 10,
					jump: function(obj, first) {
						$$timeout(function() {
							callback && callback($$.page(This.data.list, obj.curr, obj.limit, This))
						})
					}
				})
			}else{
				callback && callback(This.data.list)
			}
		}
	}
}
export default new $fn()
